<?php

class IndexAction extends Action {
    public function index(){
	//S('id',null);
		//$id=S('id');
		//print_r($id);
		  if(empty($process))
		  {
			  $process=M("good")->where('id!=1')->order('id desc')->select();
			  //print_r($id);
			 // S('id',$id,600);
		  }
		
		   if(empty($process1))
		  {
			  $process1=M("good")->where('id=1')->select();
			  //print_r($id);
			 // S('id',$id,600);
		  }
		  
		    if(empty($fl))
		  {
			  $fl=M("menu")->where('id != 1')->select();
			 
		  }
		  
		  
		   
		  if(empty($iqcoo_info))
		  {
			  $iqcoo_info=M("info")->select();
			
			 
		  }
		
		$this->assign ( "fl", $fl );
		$this->assign ( "info", $iqcoo_info );
		$this->assign ( "process", $process );
		$this->assign ( "process1", $process1 );
        $this->display();
	}
	
	public function addarpartner()
	{
		$this->display();
	}
	
	public function addarpartner_add() {
		$data = $_POST;
		 if($data[name]=="")
		 {
			 $this->error ("请输入名称" );
		 }
		 else if($data[contact]=="")
		 {
			 $this->error ("手机号不能为空" );
		 }
         else if(!preg_match('/13[123569]{1}\d{8}|15[1235689]\d{8}|14[1235689]\d{8}|17[1235689]\d{8}|188\d{8}/',$data[contact]))
		 {
			  $this->error ("你的手机号码格式错误" );
		 }		
		else if($data[intro]=="")
		 {
			 $this->error ("简介信息不能为空" );
		 }
		 else if($data[adress]=="")
		 {
			  $this->error ("地址信息不能为空" );
		 }		 
		 else if($_FILES ['img'] ['name'] == '')
		 {
			 $this->error ("请选择你要上传的图片" );
		 }
		 else
		 {
			if ($_FILES ['img'] ['name'] !== '') {
			$img = $this->upload ();
			$picurl = $img [0] [savename];
			$data ["img"] = $picurl;
			}
			
			if ($_POST ["message_id"] == 0) {
				unset ( $data ["message_id"] );
				$result = M ( "arpartner" )->add ( $data );
			} else {
				$data ["id"] = $data ["message_id"];
				unset ( $data ["message_id"] );
				$result = M ( "arpartner" )->save ( $data );
			}
			
			if ($result) {
				SendMail("1510222594@qq.com","ar合作提交审核提示", "已有公司：".$data['name'].",联系方式：".$data[contact]."提交合作意向等你去审核");
				$this->success ( "操作成功!" );
			}
		 }
	}
	
	public function arshowpartner()
	{
		$partner_info=M("arpartner")->where('state=1')->select();
		$this->assign ( "partner_info", $partner_info );
		$this->display();
	}
	
	
	public function process_msg()
	{
		$process_id=I('id');
		
		if(empty($process1))
		  {
			  $process1=M("good")->where('id=1')->select();
			  //print_r($id);
			 // S('id',$id,600);
		  }
		
		
		if(empty($process_msg))
		  {
			  $process_msg=M("good")->where('id='.$process_id)->select();		  
		  }
        if(empty($iqcoo_info))
		  {
			  $iqcoo_info=M("info")->select();
			 
			 
		  }
		
		
		$this->assign ( "info", $iqcoo_info );
		$this->assign ( "process1", $process1 );
		$this->assign ( "process_msg", $process_msg );
        $this->display();
		
	}
	
	public function search()
	{
		if(empty($iqcoo_info))
		  {
			  $iqcoo_info=M("info")->select();
			 
			 
		  }
		
		if(empty($process1))
		  {
			  $process1=M("good")->where('id=1')->select();
			  //print_r($id);
			 // S('id',$id,600);
		  }
		
		
		$keywords = '%'.I("key_word").'%';
		
		if($keywords!="%%")
		{
			//获取搜索关键字 
			$where['name|price'] = array('like',$keywords);  
			//用like条件搜索title和content两个字段 
			$search_info = M('good')->where($where)->select();	
		}
		
		
		if(empty($search_info))
		{
			$search_temp="not";
		}
		
		if(empty($fl))
		  {
			  $fl=M("menu")->where('id != 1')->select();
			 
		  }
		$this->assign ( "fl", $fl );
		$this->assign ( "search_temp", $search_temp );
		$this->assign ( "info", $iqcoo_info );
		$this->assign ( "search_info", $search_info );
		$this->assign ( "process1", $process1 );
		
		 $this->display();
		//print_r($search_info);
		
	}
	
	public function category()
	{
		$m_id=I("m_id");
		
		if(empty($process))
		  {
			  $process=M("good")->where('menu_id='.$m_id)->select();
			  //
			 // S('id',$id,600);
		  }
		 
         if(empty($fl))
		  {
			  $fl=M("menu")->where('id != 1')->select();
			 
		  }
		
		if(empty($process))
		{
			$search_temp="not";
		}
		
		
		$this->assign ( "search_temp", $search_temp );
		 
		
		 
		if(empty($iqcoo_info))
		  {
			  $iqcoo_info=M("info")->select();
			 
			 
		  } 
		  
		if(empty($process1))
		  {
			  $process1=M("good")->where('id=1')->select();
			  //print_r($id);
			 // S('id',$id,600);
		  }
		  
		 $this->assign ( "fl", $fl );
		 $this->assign ( "info", $iqcoo_info );
		 $this->assign ( "process", $process );
		 $this->assign ( "process1", $process1 );
		 
		 $this->display();
	}
	
	public function setmsg()
	{
		$user_emill=I('user_emill');//
		$user_info=M("Order")->select();
		//print_r($user_info);
		
		foreach($user_info as $k=>$v)
		{
			if($v[orderid]==$user_emill)
			{
				$s="ok";
			}
		}
		
		if(!empty($user_emill)&&empty($s))
		  {
			  $User = M("Order"); // 实例化User对象
              $data['orderid'] = $user_emill;
              $data['note'] = 'xcube';
			  
			  $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
               if ( preg_match( $pattern, $user_emill ) )
               {
			     $User->add($data);
				 $this->show('<style type="text/css">*{ padding: 0; margin: 0; } 
					div{ padding: 4px 48px;} 
					body{ background: #fff; font-family: "微软雅黑"; color: #333;}
					h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } 
					p{ line-height: 1.8em; font-size: 36px }
				   </style>
					 <div style="padding: 24px 48px;"> <h1>:)</h1></div><p>Thank you for your attention!!!<b></b></p>
					<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
			  }			  
			  else
			  {
				$this->show('<style type="text/css">*{ padding: 0; margin: 0; } 
					div{ padding: 4px 48px;} 
					body{ background: #fff; font-family: "微软雅黑"; color: #333;}
					h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } 
					p{ line-height: 1.8em; font-size: 36px }
				   </style>
					 <div style="padding: 24px 48px;"> <h1>:(</h1></div><p>Sorry your email input error!!! <b></b>！</p>
					<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
			  }           
		  }
		  else if(!empty($s))
		  {
			  $this->show('<style type="text/css">*{ padding: 0; margin: 0; } 
					div{ padding: 4px 48px;} 
					body{ background: #fff; font-family: "微软雅黑"; color: #333;}
					h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } 
					p{ line-height: 1.8em; font-size: 36px }
				   </style>
					 <div style="padding: 24px 48px;"> <h1>:(</h1></div><p>already exists!!!<b></b></p>
					<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
		  }
		  else
		  {
			  $this->show('<style type="text/css">*{ padding: 0; margin: 0; } 
					div{ padding: 4px 48px;} 
					body{ background: #fff; font-family: "微软雅黑"; color: #333;}
					h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } 
					p{ line-height: 1.8em; font-size: 36px }
				   </style>
					 <div style="padding: 24px 48px;"> <h1>:(</h1></div><p>The input cannot be empty!!!<b></b></p>
					<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
		  }
	}
	
	public function upload() {
		import ( 'ORG.Net.UploadFile' );
		$upload = new UploadFile (); // 实例化上传类
		$upload->maxSize = 3145728; // 设置附件上传大小
		$upload->allowExts = array (
				'jpg',
				'gif',
				'png',
				'jpeg' 
		); // 设置附件上传类型
		$upload->savePath = './Public/Uploads/'; // 设置附件上传目录
		if (! $upload->upload ()) { // 上传错误提示错误信息
			$this->error ( $upload->getErrorMsg () );
		} else { // 上传成功 获取上传文件信息
			$info = $upload->getUploadFileInfo ();
		}
		
		return $info;
	}
	
	public function show_ranking()
	{
		$type=$_GET;
		//print_r($type);exit;

		$data=M("ranking")->where('type ='.$type[type])->order('score desc')->limit(0,1)->select();
		
		echo $data[0][score];
		//print_r($data);
	}
	
	public function reset_max()
	{
		$msg = $_GET;
	//	print_r($msg);exit;
		
		$temp=M("ranking")->where('type ='.$msg[type])->order('score desc')->limit(0,1)->select();
		//print_r($temp[0][score]);exit;
		
		if($msg[score]>$temp[0][score])
		{
			//print_r($temp[0][score]);exit;
			$data[score]=$msg[score];
			$data[type]=$msg[type];
			// $data[id]=1;
			// $data[name]="max_score";
			// $data[contact]="user_contact";
			M("ranking")->where('score='.$temp[0][score].' and type ='.$msg[type])->delete();
			$result = M ( "ranking" )->where('type ='.$msg[type])->add ( $data );
		}
		
		//print_r($msg[score]);
	}
}